<?php
class jpgraph_pi {
	// var $lineplot = null;
    function chartgraph($ydata, $title='Chart', $chartType, $wdt_chart, $hgh_chart,$axis_coor, $fill_color, $grad_x, $start_color, $end_color )
    {
        require_once("jpgraph/jpgraph.php");
        require_once("jpgraph/jpgraph_line.php");    
        require_once("jpgraph/jpgraph_bar.php");    
        require_once("jpgraph/jpgraph_pie.php");    
        require_once("jpgraph/jpgraph_pie3d.php");    
        
        // Create the graph. These two calls are always required
        $graph = new Graph($wdt_chart,$hgh_chart,"auto",60);
        $graph->SetScale("textlin"); 
        // $graph->SetColor('red');
		// Show both major and minor grid lines
		// $graph->axis->ShowGrid(true,true);

		// Set color for gradient lines
		// $graph->axis->SetGridColor('lightblue:0.9','lightblue:0.9','lightblue:0.9');

		// Set label and axis colors
		// $graph->axis->SetColor('black','navy','darkred');		
		// $graph->SetFrame(true,'blue ',2);
		
		
		$graph->SetMargin(30,90,30,30);
		if($axis_coor == 1)
		{
			
			$graph->img->SetAngle(90);
		}
		
		$graph->title->SetFont(FF_FONT1,FS_BOLD);
		$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
		$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
		if($fill_color != false){
			$graph->xaxis->SetColor($fill_color); 
			$graph->yaxis->SetColor($fill_color); 
		}else{
			$graph->xaxis->SetColor("#ff00fa"); 
			$graph->yaxis->SetColor("#ff00fa"); 
		}
		
        //Create the plot 
		
		if($chartType == "line"){
			$lineplot=new LinePlot($ydata); 
			$lineplot->SetColor($start_color);
			// if($grad_x == 1)
			// {	
				// $lineplot->SetFillGradient($start_color,$end_color,GRAD_VERT);
			// }
			
			$graph->Add($lineplot);
		}
		else if($chartType == "bar"){
			$barplot=new BarPlot($ydata);  
			$tcol=array(100,100,255);

			$fcol=array(255,100,100);

			$barplot->SetShadow("steelblue",2,2);
			$barplot->value->Show();
			$barplot->value->SetFormat('%d');
			$barplot->value->SetFont(FF_FONT1,FS_BOLD);

			// Center the values in the bar
			$barplot->SetValuePos('center');

			// Make the bar a little bit wider 
			// $barplot->SetShadow("black",3);
			if($grad_x == 1)
			{	
				$barplot->SetFillGradient($start_color,$end_color,GRAD_VERT);
			}
			// else{
				// $barplot->SetFillColor($start_color);
			// }
			// $barplot->value->SetColor("black","navy"); 
			$graph->Add($barplot);  
		}
		else if($chartType == "acc"){
			$graph->SetShadow();
			$accbar = array();
			$count_val = count($ydata);
			for($i=0; $i < $count_val ; $i++)
			{ 
				$accbar[$i] = new BarPlot($ydata[$i]);
				
				$accbar[$i]->value->Show();
				$accbar[$i]->value->SetFormat('%d');
				$accbar[$i]->value->SetFont(FF_FONT1,FS_BOLD);
				$accbar[$i]->SetValuePos('center');

				// Make the bar a little bit wider
				$accbar[$i]->SetWidth(0.7);
				// if($grad_x == 1)
				// {	
					// $accbar[$i]->SetFillGradient($start_color,$end_color,GRAD_VERT);
				// }
			} 
			
			$gbplot = new AccBarPlot($accbar);
			

			$gbplot->SetShadow();
			$graph->Add($gbplot);
			
		}
		else if($chartType == "pie"){
			$graph=new PieGraph(300,200);
			$graph->SetShadow();
			
			$pieplot = new PiePlot($ydata);
			// if($grad_x == 1)
			// {	
				// $pieplot->SetFillGradient($start_color,$end_color,GRAD_VERT);
			// }
			$pieplot->value->Show(false);
			$graph->Add($pieplot);
		}
		else if($chartType == "ring"){
			$graph=new PieGraph(300,200);
			$graph->SetShadow();
			
			$pieplot = new PiePlotC($ydata);
			// if($grad_x == 1)
			// {	
				// $pieplot->SetFillGradient($start_color,$end_color,GRAD_VERT);
			// }
			// $pieplot->value->Show(false);
			
			// Set size of pie
			$pieplot->SetSize(0.32);
			$pieplot->value->Show(false);
			// Label font and color setup
			// $pieplot->value->SetFont(FF_ARIAL,FS_BOLD,10);
			// $pieplot->value->SetColor('black');
			  
			 
			// Set color for mid circle 
			 
			// Use percentage values in the legends values (This is also the default)
			// $pieplot->SetLabelType(PIE_VALUE_PER);
			$graph->Add($pieplot);
		}
		else if($chartType == "3Dpie"){
			$graph  = new PieGraph(350,250);
			
			$theme_class= new VividTheme;
			$graph->SetTheme($theme_class);
			
			$pieplot = new PiePlot3D($ydata);
			// if($grad_x == 1)
			// {	
				// $pieplot->SetFillGradient($start_color,$end_color,GRAD_VERT);
			// }
			$pieplot->value->Show(false);
			$graph->Add($pieplot);
			
			$pieplot->ShowBorder();
			$pieplot->SetColor('black');
			$pieplot->ExplodeSlice(1); 
		} 
		
		 
        
        return $graph; // does PHP5 return a reference automatically?
    }
}
?>